package com.itheima.project.web;

import com.itheima.project.entity.UserAuth;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName
 * @Description
 */
@RestController
public class HelloController {
    @RequestMapping("/hello/user")
    public String helloUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String name = authentication.getName();
        return "hello-user  "+name;
    }


    @RequestMapping("/hello/admin")
    public String helloAdmin(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String name = authentication.getName();
        return "hello-admin  "+name;
    }

}


/*

 */
/**
 * 测试接口
 * 修改代码 version 1.0
 * @return
 *//*

    @RequestMapping("/hello")
    public String hello() {
        //获取当前登录用户名称
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        //取出认证主体对象
        UserAuth userAuth = (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        return "hello :" + name + "  昵称：" + userAuth.getNickName();
    }
*/